/*
 * Copyright 2009 Max Kugland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.splink.deepsplink.authentication {
	import org.splink.library.distributor.Distributor;

	/**
	 * Convenience <code>IAuthenticator</code> base class. Create a subclass and override 
	 * the <code>authenticate</code> method and implement your authentication process.
	 * 
	 * @author Max Kugland
	 */
	public class BaseAuthenticator extends Distributor implements IAuthenticator {
		protected var _isAuthenticated : Boolean = false;

		public function BaseAuthenticator() {
		}

		/**
		 * Override <code>authenticate</code> and implement your authentication. When your
		 * authentication process completes either invoke <code>distributeSuccessEvent</code>
		 * or <code>distributeFailureEvent</code>
		 * 
		 * @inheritDoc
		 */
		public function login(data : *) : void {
		}

		public function logout() : void {
		}

		/**
		 * @inheritDoc
		 */
		final public function isAuthenticated() : Boolean {
			return _isAuthenticated;
		}

		final protected function distributeLoginSuccessEvent(data : * = null) : void {
			distribute(new AuthenticatorEvent(this, AuthenticatorEvent.LOGIN_SUCCESS, data));
		}

		final protected function distributeLoginFailureEvent(data : * = null) : void {
			distribute(new AuthenticatorEvent(this, AuthenticatorEvent.LOGIN_FAILURE, data));
		}

		final protected function distributeLogoutSuccessEvent(data : * = null) : void {
			distribute(new AuthenticatorEvent(this, AuthenticatorEvent.LOGOUT_SUCCESS, data));
		}
	}
}
